<?php echo $this->render('/public/header');?>
<script src="https://cdn.bootcss.com/element-ui/1.4.2/index.js"></script>
<link href="https://cdn.bootcss.com/element-ui/1.4.2/theme-default/index.css" rel="stylesheet">
<div id="main" class="col-lg-12 col-xs-12 col-sm-12 col-md-12">
    <div v-for="(v,k) in this.list" style="margin:30px">
        <label >采购:{{v.job_number}}</label>{{v.name}}{{v['saleman']}}
        <br/>
        <br/>
        <span v-for="v2 in saleman" style="margin-left:10px">
            <label>{{v2.name}}{{v2.job_number}}</label>
            <input v-model="fiter_checked(v['saleman'])" type="checkbox" @change="update_saleman(v.name,v.job_number)" :value="v2.job_number"  :name="v.name+'_'+v.job_number" style="width:15px;height:13px" />
        </span>
    </div>
</div>
<script>
var vm = new Vue({
    el:"#main",
    data:{
        list:<?php echo json_encode($this->params['list']['purchase']);?>,
        saleman:<?php echo json_encode($this->params['list']['saleman']);?>
    },
    methods:{
        fiter_checked:function(arr){
            if (typeof arr == "string") {
                return JSON.parse(arr);
            }
            return [];
        },
        update_saleman:function(purchase_name,purchase_job_number) {
            var name=purchase_name+'_'+purchase_job_number;
            var arr = [];
            $("input[name="+name+"]").each(function(){
                if($(this)[0].checked) {
                    arr.push($(this).val());
                }
            })
            arr = JSON.stringify(arr);
            layer.confirm("确认修改",{},function(){
                $.post('/setting/update_purchases_saleman',{data:arr,purchase:purchase_job_number},function(res){
                    if(res.code==1){
                        layer.confirm("修改成功",{},function(){
                            window.location.reload();
                        })
                    }else
                    {
                        layer.alert(res.msg);
                    }
                },'json')
            })
        }
    }
})
</script>
<?php echo $this->render('/public/footer');?>
